import { tableOption, tableOption1 } from './list_table.config.js'
import search from './../search/search.js';
import { getGoodsStockRecordPage, getStockRecordDetailList } from '@/api/shop/stock/list.js'

export default {
    name: "list_table",
    mixins: [search],
    components: {
    },
    data() {
        return {
            tableOption,
            loading: false,
            loadData: [],
            page: {
                current: 1,
                total: 0,
                size: 10
            },
            btn: [
                // {
                //     title: "新增采购单",
                //     isShow: true
                // },
                // {
                //     title: "导出",
                //     isShow: true
                // }
            ],
            selectedRows: [],  //选中的数组

            dialogVisible: false,   //库存流水
            tableOption1,
            loading1: false,
            loadData1: [],

            billStatus: [
                {
                    label: '采购入库',
                    value: '00'
                },
                {
                    label: '采购退货入库',
                    value: '01'
                },
                {
                    label: '配送出库',
                    value: '02'
                }, {
                    label: '门店退货入库',
                    value: '03'
                },
                {
                    label: '门店销售',
                    value: '04'
                }, {
                    label: '门店退货',
                    value: '05'
                }, {
                    label: '门店盘盈入库',
                    value: '06'
                }, {
                    label: '门店盘亏出库',
                    value: '07'
                }, {
                    label: '平台推送到门店入库',
                    value: '08'
                }, {
                    label: '门店主动退货出库',
                    value: '09'
                }
            ]
        }
    },
    methods: {
        getList(searchForm, page) {
            if (searchForm) {
                console.log(searchForm)
            }
            if (page) {
                this.page.current = page
            }
            this.loading1 = true
            getGoodsStockRecordPage(Object.assign({ deptId: this.$store.getters.userInfo.sysUser.deptId, tenantId: this.$store.getters.userInfo.sysUser.tenantId }, searchForm ? searchForm : {}, this.page)).then(val => {
                console.log(val)
                let data = val.data
                this.page = {
                    current: data.current,
                    total: data.total,
                    size: data.size,
                }
                this.loadData = data.records
                this.loading1 = false
            }).catch(() => {
                this.loading1 = false
            })
        },
        onShowSizeChange(current, size) {
            console.log(current, size)
            this.page.current = current
            this.page.size = size
            this.getList()
        },
        selectionChange(list) {
            this.selectedRows = list
        },
        handler(index) {
            if (index == 0) {
                this.export()
            }
        },
        kucunLs(item) {  //编辑
            this.dialogVisible = true
            this.loading1 = true
            getStockRecordDetailList({ shopId: item.shopId, goodsId: item.goodsId }).then(val => {
                console.log(val)
                let data = val.data
                this.loadData1 = data
                this.loadData1.forEach(item => {
                    if (item.operationType == '00') {
                        item.operatioNum = '+' + item.operatioNum
                    } else if (item.operationType == '01') {
                        item.operatioNum = '-' + item.operatioNum
                    }
                    this.billStatus.forEach(items => {
                        if (items.value == item.billStatus) {
                            item.billStatus1 = items.label
                        }
                    })

                });
                this.loading1 = false
            }).catch(() => {
                this.loading1 = false
            })
        },
        export() {

        }
    }

} 